import { action, observable } from 'mobx'
import orderService from '../services/order/orderService'
import { UserShippingAddressDto } from '../services/cart/dto/userShippingAddressDto'
import { UserShippingAddressInputDto } from '../services/cart/dto/userShippingAddressInputDto'
import { AreaForCascaderModel } from '../services/cart/dto/areaForCascaderModel'
import { ProductForOrder } from '../services/order/dto/productForOrder'
import { OrderModel } from '../services/order/dto/orderModel'
import { JsSdkDto } from '../services/dto/jsSdkDto'
import { JsApiReturnModel } from '../services/dto/jsApiReturnModel'
import { PayResultModel } from '../services/dto/payResultModel'
import { OrderDto } from '../services/order/dto/orderDto';
import { MyOrderPagedQueryDto } from '../services/order/dto/myOrderPagedQueryDto';
import { PagedList } from '../services/dto/pagedList';
import { ProductForShopQueryDto } from '../services/order/dto/productForShopQueryDto';
import { OrderScoreInputDto } from '../services/order/dto/orderScoreInputDto';
import { OrderCountDto } from '../services/order/dto/orderCountDto';

class OrderStore {
    @observable addressList: UserShippingAddressDto[]
    @observable address: UserShippingAddressDto
    @observable areas: AreaForCascaderModel[]
    @observable parentsAreas: AreaForCascaderModel[]
    @observable area: AreaForCascaderModel
    @observable orderProducts: ProductForOrder[]
    @observable jsSdk: JsSdkDto
    @observable jsApiModel: JsApiReturnModel
    @observable orderId: string
    @observable payResult: PayResultModel
    @observable order: OrderDto
    @observable orders: PagedList<OrderDto>
    @observable districts: AreaForCascaderModel[][]
    @observable orderScoreId: number
    @observable orderCount: OrderCountDto
    @action
    async getMyAddressList() {
        await orderService.getMyAddressList().then((res) => {
            this.addressList = res.data.result
        })
    }

    @action
    async getUserShippingAddress(id: number) {
        await orderService.getUserShippingAddress(id).then((res) => {
            this.address = res.data.result
        })
    }

    @action
    async getMyDefaultShippingAddress() {
        await orderService.getMyDefaultShippingAddress().then((res) => {
            this.address = res.data.result
        })
    }

    @action
    async createOrUpdateUserShippingAddress(input: UserShippingAddressInputDto) {
        await orderService.createOrUpdateUserShippingAddressAsync(input).then((res) => {
            this.address = res.data.result
        })
    }

    @action
    async deleteUserShippingAddress(id: number) {
        await orderService.deleteUserShippingAddress(id)
    }

    @action
    async getAreas(id: string) {
        await orderService.getAreas(id).then((res) => {
            this.areas = res.data.result
        })
    }

    @action
    async getAreaAndParents(id: string) {
        await orderService.getAreaAndParents(id).then((res) => {
            this.parentsAreas = res
        })
    }

    @action
    async getAreaParentsAndSiblings(code: string) {
        await orderService.getAreaParentsAndSiblings(code).then((res) => {
            this.districts = res
        })
    }

    @action
    async getAreaByName(name: string) {
        await orderService.getAreaByName(name).then((res) => {
            this.area = res
        })
    }

    @action
    async getOrderProductsByCartIds(ids: number[]) {
        await orderService.getOrderProductsByCartIds(ids).then((res) => {
            this.orderProducts = res
        })
    }

    @action
    async getProductsForShop(input: ProductForShopQueryDto[]) {
        await orderService.getProductsForShop(input).then((res) => {
            this.orderProducts = res
        })
    }

    @action
    async createOrder(model: OrderModel) {
        await orderService.createOrder(model).then((res) => {
            this.orderId = res.id
        })
    }

    @action
    async getJsApi() {
        await orderService.getJsApi().then((res) => {
            this.jsSdk = res
        })
    }

    @action
    async getApiPay(orderId: string) {
        await orderService.getApiPay(orderId).then((res) => {
            this.jsApiModel = res
        })
    }

    @action
    async getPayStatus(orderId: string) {
        await orderService.getPayStatus(orderId).then((res) => {
            this.payResult = res
        })
    }

    @action
    async getMyOrderDetail(orderId: string) {
        await orderService.getMyOrderDetail(orderId).then((res) => {
            this.order = res
        })
    }

    @action
    async getOrderDetail(orderId: string) {
        await orderService.getOrderDetail(orderId).then((res) => {
            this.order = res
        })
    }

    @action
    async getMyOrderPagedList(input: MyOrderPagedQueryDto) {
        await orderService.getMyOrderPagedList(input).then((res) => {
            this.orders = res
        })
    }

    @action
    async cancelOrder(id: string) {
        await orderService.cancelOrder(id)
    }

    @action
    async confirmReceive(id: string) {
        await orderService.confirmReceive(id)
    }

    @action
    async deleteOrder(id: string) {
        await orderService.deleteOrder(id)
    }

    @action
    async createOrderScore(model: OrderScoreInputDto) {
        await orderService.createOrderScore(model).then((res) => {
            this.orderScoreId = res
        })
    }

    @action
    async getMyOrderCount(moduleTypeIds: string[]) {
        await orderService.getMyOrderCount(moduleTypeIds).then((res) => {
            this.orderCount = res
        })
    }

    @action
    async confirmOrder(orderId: string) {
        await orderService.confirmOrder(orderId)
    }

    @action
    async changeOrderUserShippingAddress(userShippingAddressId: number, id: string) {
        await orderService.changeOrderUserShippingAddress(userShippingAddressId, id)
    }
}

export default OrderStore 